home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWMenu / FWMnuBar.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  8.6 KB  |  279 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWMnuBar.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWMNUBAR_H
  11. #define FWMNUBAR_H
  12.  
  13. #ifndef FWPULLDM_H
  14. #include "FWPullDM.h"
  15. #endif
  16.  
  17. #ifndef FWCOMMON_H
  18. #include "FWCommon.h"
  19. #endif
  20.  
  21. #ifndef FWDEBUG_H
  22. #include "FWDebug.h"
  23. #endif
  24.  
  25. #ifndef FWTCOLL_H
  26. #include "FWTColl.h"
  27. #endif
  28.  
  29. // ----- OpenDoc Includes -----
  30.  
  31. #ifndef SOM_ODMenuBar_xh
  32. #include <MenuBar.xh>
  33. #endif
  34.  
  35. // ----- Platform Includes -----
  36.  
  37. #if defined(FW_BUILD_WIN) && !defined(_INC_WINDOWS)
  38. #include <windows.h>
  39. #endif
  40.  
  41. //========================================================================================
  42. //    Forward class definitions
  43. //========================================================================================
  44.  
  45. class ODPart;
  46. class FW_CString;
  47. class FW_CMenuItem;
  48.  
  49. //========================================================================================
  50. //    class FW_CMenuBar
  51. //========================================================================================
  52.  
  53. class FW_CMenuBar
  54. {
  55. //----------------------------------------------------------------------------------------
  56. //    Constructors/Destructors
  57. //
  58. public:
  59.     FW_DECLARE_AUTO(FW_CMenuBar)
  60.  
  61.     FW_CMenuBar(Environment* ev, ODPart* thePart, FW_Instance partInstance);
  62.     virtual ~FW_CMenuBar();
  63.     
  64. //----------------------------------------------------------------------------------------
  65. //    New API
  66. //
  67. public:
  68.     // ----- Adding -----
  69.     void                InitializeFromResource(Environment* ev, FW_ResourceID menuBarResourceID);
  70.     void                InitializeFromStream(Environment* ev, FW_CReadableStream& stream);
  71.     
  72.     void                 AdoptMenuFirst(Environment* ev, 
  73.                             FW_CPullDownMenu* menu);
  74.     void                 AdoptMenuLast(Environment* ev, 
  75.                             FW_CPullDownMenu* menu);
  76.                             
  77.     void                 AdoptMenuBefore(Environment* ev, 
  78.                             FW_CPullDownMenu* menu, 
  79.                             FW_CPullDownMenu* beforeMenu);    // if beforeMenu == NULL -> AdoptMenuFirst
  80.     void                 AdoptMenuAfter(Environment* ev, 
  81.                             FW_CPullDownMenu* menu, 
  82.                             FW_CPullDownMenu* afterMenu);    // if afterMenu == NULL -> AdoptMenuLast
  83.  
  84.     // ----- Removing/Detaching -----
  85.     void                 DetachMenu(Environment* ev, 
  86.                             FW_CPullDownMenu* menuToDetach);    
  87.     void                 DeleteMenu(Environment* ev, 
  88.                             FW_CPullDownMenu* menuToDelete);    // DetachMenu + delete of the menu
  89.     void                 DeleteAll(Environment* ev);
  90.  
  91.     void                RemoveItem(Environment* ev, ODCommandID commandID);
  92.     
  93.     // ----- Item access -----
  94.     void                 SetItemString(Environment* ev,
  95.                             ODCommandID commandID, 
  96.                             const FW_CString& itemString);
  97.     void                 GetItemString(Environment* ev, 
  98.                             ODCommandID commandID, 
  99.                             FW_CString& itemString) const;
  100.     
  101.     FW_CString            GetAboutString(Environment* ev) const;
  102.  
  103.     void                 EnableCommand(Environment* ev, 
  104.                             ODCommandID cmdNumber, 
  105.                             FW_Boolean enable);
  106.     void                 CheckCommand(Environment* ev, 
  107.                             ODCommandID cmdNumber, 
  108.                             FW_Boolean check);
  109.     void                 ToggleItem(Environment* ev, 
  110.                             ODCommandID cmdNumber, 
  111.                             FW_Boolean toggleState);
  112.                             
  113.     void                 EnableAndCheckCommand(Environment* ev, 
  114.                             ODCommandID cmdNumber, 
  115.                             FW_Boolean enable,
  116.                             FW_Boolean check);
  117.     void                 EnableAndToggleCommand(Environment* ev, 
  118.                             ODCommandID cmdNumber, 
  119.                             FW_Boolean enable,
  120.                             FW_Boolean toggleState);
  121.  
  122.     FW_MenuKey            GetMenuKey(Environment* ev, ODCommandID cmdNumber) const;
  123.     void                SetMenuKey(Environment* ev, ODCommandID cmdNumber, FW_MenuKey menuKey);
  124.                         
  125.     void                DisableAll(Environment* ev);
  126.     void                EnableAll(Environment* ev);
  127.     
  128.     // ----- Getters/Setters -----    
  129.     FW_CMenuItem*        GetMenuItemFromCommand(Environment* ev, 
  130.                             ODCommandID cmdNumber) const;
  131.                                 
  132.     ODMenuBar*            AcquireODMenuBar(Environment* ev) const;
  133.     ODPart*                GetODPart(Environment* ev) const;
  134.     
  135.     FW_CPullDownMenu*     FindMenuWithID(Environment* ev, ODMenuID menu) const;
  136.  
  137. //----------------------------------------------------------------------------------------
  138. //    Internal API
  139. //
  140. public:
  141.     void                 PrivDisplay(Environment* ev);    
  142.     
  143.     ODMenuID            PrivGetNewMenuID(Environment* ev);
  144.  
  145. #ifdef FW_BUILD_MAC
  146.     void                PrivMacEnableParentItem(Environment* ev, 
  147.                             ODCommandID cmdNumber);
  148.     
  149.     void                PrivMacRegisterCommand(Environment* ev,
  150.                             ODCommandID commandID,
  151.                             ODMenuID menuID,
  152.                             short itemID);
  153.     void                PrivMacUnregisterCommand(Environment* ev,
  154.                             ODCommandID commandID);
  155.     ODCommandID            PrivMacGetCommand(Environment* ev,
  156.                             ODMenuID menuID,
  157.                             short itemID);
  158.     
  159. #endif
  160.  
  161.     void                PrivAddSubMenu(Environment* ev,
  162.                             ODMenuID subMenuID,
  163.                             ODPlatformMenu platformMenu);
  164.     void                PrivRemoveMenu(Environment* ev, 
  165.                                         ODMenuID menuID);
  166.                             
  167. //----------------------------------------------------------------------------------------
  168. //    Platform specific API
  169. //
  170. #ifdef FW_BUILD_MAC
  171. public:
  172.     // ----- Enable/Disable of the whole menuBar -----
  173.     void                MacEnableMenuBar(Environment* ev, 
  174.                             FW_Boolean enable);
  175. #endif
  176.                         
  177. //----------------------------------------------------------------------------------------
  178. //    Data Members
  179. //
  180. private:
  181.     ODMenuBar*                                        fODMenuBar;
  182.     ODPart*                                            fODPart;
  183.     FW_TOrderedCollection<FW_CPullDownMenu>*        fPullDownMenuList;
  184.     ODMenuID                                        fNextMenuID;
  185.     FW_Instance                                        fPartInstance;
  186.     FW_CString                                        fAboutString;
  187. };
  188.  
  189. //========================================================================================
  190. //    FW_CMenuBar inlines
  191. //========================================================================================
  192.  
  193. //----------------------------------------------------------------------------------------
  194. //    FW_CMenuBar::PrivDisplay
  195. //----------------------------------------------------------------------------------------
  196. inline void FW_CMenuBar::PrivDisplay(Environment* ev)
  197. {
  198.     fODMenuBar->Display(ev);
  199. }
  200.  
  201. //----------------------------------------------------------------------------------------
  202. //    FW_CMenuBar::GetODPart
  203. //----------------------------------------------------------------------------------------
  204. inline ODPart* FW_CMenuBar::GetODPart(Environment*) const
  205. {
  206.     return fODPart;
  207. }
  208.  
  209. //----------------------------------------------------------------------------------------
  210. //    FW_CMenuBar::PrivGetNewMenuID
  211. //----------------------------------------------------------------------------------------
  212. inline ODMenuID FW_CMenuBar::PrivGetNewMenuID(Environment*)
  213. {
  214.     FW_ASSERT(fNextMenuID < 254);    // was 255; now 255 is used for unattached menu ID
  215.     return fNextMenuID++;
  216. }
  217.  
  218. #ifdef FW_BUILD_MAC
  219. //----------------------------------------------------------------------------------------
  220. //    FW_CMenuBar::PrivMacRegisterCommand
  221. //----------------------------------------------------------------------------------------
  222. inline void FW_CMenuBar::PrivMacRegisterCommand(Environment* ev,
  223.                                                 ODCommandID commandID,
  224.                                                 ODMenuID menuID,
  225.                                                 short itemID)
  226. {
  227.     fODMenuBar->RegisterCommand(ev, commandID, menuID, itemID);
  228. }
  229. #endif
  230.  
  231. #ifdef FW_BUILD_MAC
  232. //----------------------------------------------------------------------------------------
  233. //    FW_CMenuBar::PrivMacUnregisterCommand
  234. //----------------------------------------------------------------------------------------
  235. inline void FW_CMenuBar::PrivMacUnregisterCommand(Environment* ev,
  236.                                                 ODCommandID commandID)
  237. {
  238.     fODMenuBar->UnregisterCommand(ev, commandID);
  239. }
  240. #endif
  241.     
  242. #ifdef FW_BUILD_MAC
  243. //----------------------------------------------------------------------------------------
  244. //    FW_CMenuBar::PrivMacGetCommand
  245. //----------------------------------------------------------------------------------------
  246. inline ODCommandID FW_CMenuBar::PrivMacGetCommand(Environment* ev,
  247.                                                 ODMenuID menuID,
  248.                                                 short itemID)
  249. {
  250.     return fODMenuBar->GetCommand(ev, menuID, itemID);
  251. }
  252. #endif
  253.     
  254. //----------------------------------------------------------------------------------------
  255. //    FW_CMenuBar::PrivAddSubMenu
  256. //----------------------------------------------------------------------------------------
  257. inline void FW_CMenuBar::PrivAddSubMenu(Environment* ev,
  258.                                         ODMenuID subMenuID,
  259.                                         ODPlatformMenu platformMenu)
  260. {
  261. #ifdef FW_BUILD_MAC
  262.     fODMenuBar->AddSubMenu(ev, subMenuID, platformMenu, fODPart);
  263. #endif
  264. #ifdef FW_BUILD_WIN
  265.     // [WIN_PORT] AddSubMenu is missing in OpenDoc/Win!
  266. #endif
  267. }
  268.  
  269. //----------------------------------------------------------------------------------------
  270. //    FW_CMenuBar::PrivRemoveMenu
  271. //----------------------------------------------------------------------------------------
  272. inline void FW_CMenuBar::PrivRemoveMenu(Environment* ev, 
  273.                                         ODMenuID menuID)
  274. {
  275.     fODMenuBar->RemoveMenu(ev, menuID);
  276. }
  277.  
  278. #endif
  279.